package com.example.fms.vo;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ResponseBean<T> implements Serializable {
    private int code;
    private String msg;
    private T data;
    private Meta meta;



    public static <T> ResponseBean success() {
        return ResponseBean.builder()
                .code(HttpStatus.OK.value())
                .msg(HttpStatus.OK.getReasonPhrase())
                .build();
    }

    public static <T> ResponseBean success(T data) {
        return ResponseBean.builder()
                .code(HttpStatus.OK.value())
                .msg(HttpStatus.OK.getReasonPhrase())
                .data(data)
                .build();
    }

    public static <T> ResponseBean successMeat(T data) {
        return ResponseBean.builder()
                .code(HttpStatus.OK.value())
                .msg(HttpStatus.OK.getReasonPhrase())
                .meta(new Meta(HttpStatus.OK.getReasonPhrase(), HttpStatus.OK.value()))
                .data(data)
                .build();
    }

    public static <T> ResponseBean success(String msg) {
        return ResponseBean.builder()
                .code(HttpStatus.OK.value())
                .msg(msg)
                .build();
    }

    public static <T> ResponseBean success(String msg, T date) {
        return ResponseBean.builder()
                .code(HttpStatus.OK.value())
                .msg(msg)
                .data(date)
                .build();
    }

    public static <T> ResponseBean<T> successFactory() {
        return new ResponseBean<T>(200, "success", null,null);
    }



    public static <T> ResponseBean failed() {
        return ResponseBean.builder()
                .code(HttpStatus.INTERNAL_SERVER_ERROR.value())
                .msg(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
                .build();
    }

    public static <T> ResponseBean failed(String msg) {
        return ResponseBean.builder()
                .code(HttpStatus.INTERNAL_SERVER_ERROR.value())
                .msg(msg)
                .build();
    }

    public static <T> ResponseBean failed(int code, String msg) {
        return ResponseBean.builder()
                .code(code)
                .msg(msg)
                .build();
    }

    public static <T> ResponseBean failed(int code, String msg,Meta meta) {
        return ResponseBean.builder()
                .code(code)
                .msg(msg)
                .meta(meta)
                .build();
    }



}
